package com.example.auth.exception;
import com.example.common.utils.ResponseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 基础异常
     */
    @ExceptionHandler(BaseException.class)
    public ResponseResult baseException(BaseException e) {
        log.warn(e.getMessage(), e);
        log.info("e.getMessage(){}",e.getMessage());
        return ResponseResult.error();
    }
    /**
     * 业务异常
     */
    @ExceptionHandler(BusinessException.class)
    public ResponseResult businessException(BusinessException e) {
        log.warn(e.getMessage(), e);
        if (null ==e.getCode()) {
            return ResponseResult.error();
        }
        log.info("getCode(){}, e.getMessage(){}",e.getCode(),e.getMessage());
        return ResponseResult.error();
    }
}
